home *** CD-ROM | disk | FTP | other *** search
-
- # line 20 "posixtm.y"
- #ifdef __GNUC__
- #define alloca __builtin_alloca
- #else
- #ifdef sparc
- #include <alloca.h>
- #else
- #ifdef _AIX
- #pragma alloca
- #else
- char *alloca ();
- #endif
- #endif
- #endif
- # define digit 257
-
- # line 38 "posixtm.y"
- #include <stdio.h>
- #include <sys/types.h>
- #include <time.h>
-
- #define YYDEBUG 1
-
- static char *curpos;
-
- static struct tm t;
-
- time_t mktime ();
-
- static int zzlex ();
- #define zzparse posixtime_zzparse
- static int zzerror ();
- #define zzclearin zzchar = -1
- #define zzerrok zzerrflag = 0
- extern int zzchar;
- extern int zzerrflag;
- #ifndef YYMAXDEPTH
- #define YYMAXDEPTH 150
- #endif
- #ifndef YYSTYPE
- #define YYSTYPE int
- #endif
- YYSTYPE zzlval, zzval;
- typedef int zztabelem;
- # define YYERRCODE 256
-
- # line 126 "posixtm.y"
-
- static int
- zzlex ()
- {
- char ch = *curpos++;
-
- if (ch >= '0' && ch <= '9')
- {
- zzlval = ch - '0';
- return digit;
- }
- else if (ch == '.' || ch == '\0')
- return ch;
- else
- /* Cause an error. */
- return '?';
- }
-
- static int
- zzerror ()
- {
- return 0;
- }
-
- /* Parse a POSIX-style date and return it, or (time_t)-1 for an error. */
-
- time_t
- posixtime (s)
- char *s;
- {
- curpos = s;
- /* Let mktime() decide whether it is daylight savings time. */
- t.tm_isdst = -1;
- if (zzparse ())
- return (time_t)-1;
- else
- return mktime (&t);
- }
-
- /* Parse a POSIX-style date and return it, or NULL for an error. */
-
- struct tm *
- posixtm (s)
- char *s;
- {
- if (posixtime (s) == -1)
- return NULL;
- return &t;
- }
- zztabelem zzexca[] ={
- -1, 1,
- 0, -1,
- -2, 0,
- };
- # define YYNPROD 8
- # define YYLAST 16
- zztabelem zzact[]={
-
- 3, 5, 11, 2, 10, 8, 4, 1, 6, 0,
- 7, 9, 0, 12, 0, 13 };
- zztabelem zzpact[]={
-
- -257, -1000, -257, -256, -257, -1000, -257, -257, -44, -257,
- -1000, -257, -1000, -1000 };
- zztabelem zzpgo[]={
-
- 0, 7, 3, 5, 4 };
- zztabelem zzr1[]={
-
- 0, 1, 3, 3, 3, 4, 4, 2 };
- zztabelem zzr2[]={
-
- 0, 13, 3, 5, 1, 1, 5, 5 };
- zztabelem zzchk[]={
-
- -1000, -1, -2, 257, -2, 257, -2, -2, -3, -2,
- -4, 46, -2, -2 };
- zztabelem zzdef[]={
-
- 0, -2, 0, 0, 0, 7, 0, 4, 5, 2,
- 1, 0, 3, 6 };
- typedef struct { char *t_name; int t_val; } zztoktype;
- #ifndef YYDEBUG
- # define YYDEBUG 0 /* don't allow debugging */
- #endif
-
- #if YYDEBUG
-
- zztoktype zztoks[] =
- {
- "digit", 257,
- "-unknown-", -1 /* ends search */
- };
-
- char * zzreds[] =
- {
- "-no such reduction-",
- "date : digitpair digitpair digitpair digitpair year seconds",
- "year : digitpair",
- "year : digitpair digitpair",
- "year : /* empty */",
- "seconds : /* empty */",
- "seconds : '.' digitpair",
- "digitpair : digit digit",
- };
- #endif /* YYDEBUG */
- /* @(#)yaccpar 1.10 */
- /*
- ** Skeleton parser driver for yacc output
- */
-
- /*
- ** yacc user known macros and defines
- */
- #define YYERROR goto zzerrlab
- #define YYACCEPT return(0)
- #define YYABORT return(1)
- #define YYBACKUP( newtoken, newvalue )\
- {\
- if ( zzchar >= 0 || ( zzr2[ zztmp ] >> 1 ) != 1 )\
- {\
- zzerror( "syntax error - cannot backup" );\
- goto zzerrlab;\
- }\
- zzchar = newtoken;\
- zzstate = *zzps;\
- zzlval = newvalue;\
- goto zznewstate;\
- }
- #define YYRECOVERING() (!!zzerrflag)
- #ifndef YYDEBUG
- # define YYDEBUG 1 /* make debugging available */
- #endif
-
- /*
- ** user known globals
- */
- int zzdebug; /* set to 1 to get debugging */
-
- /*
- ** driver internal defines
- */
- #define YYFLAG (-1000)
-
- /*
- ** global variables used by the parser
- */
- YYSTYPE zzv[ YYMAXDEPTH ]; /* value stack */
- int zzs[ YYMAXDEPTH ]; /* state stack */
-
- YYSTYPE *zzpv; /* top of value stack */
- int *zzps; /* top of state stack */
-
- int zzstate; /* current state */
- int zztmp; /* extra var (lasts between blocks) */
-
- int zznerrs; /* number of errors */
- int zzerrflag; /* error recovery flag */
- int zzchar; /* current input token number */
-
-
-
- /*
- ** zzparse - return 0 if worked, 1 if syntax error not recovered from
- */
- int
- zzparse()
- {
- register YYSTYPE *zzpvt; /* top of value stack for $vars */
-
- /*
- ** Initialize externals - zzparse may be called more than once
- */
- zzpv = &zzv[-1];
- zzps = &zzs[-1];
- zzstate = 0;
- zztmp = 0;
- zznerrs = 0;
- zzerrflag = 0;
- zzchar = -1;
-
- goto zzstack;
- {
- register YYSTYPE *zz_pv; /* top of value stack */
- register int *zz_ps; /* top of state stack */
- register int zz_state; /* current state */
- register int zz_n; /* internal state number info */
-
- /*
- ** get globals into registers.
- ** branch to here only if YYBACKUP was called.
- */
- zznewstate:
- zz_pv = zzpv;
- zz_ps = zzps;
- zz_state = zzstate;
- goto zz_newstate;
-
- /*
- ** get globals into registers.
- ** either we just started, or we just finished a reduction
- */
- zzstack:
- zz_pv = zzpv;
- zz_ps = zzps;
- zz_state = zzstate;
-
- /*
- ** top of for (;;) loop while no reductions done
- */
- zz_stack:
- /*
- ** put a state and value onto the stacks
- */
- #if YYDEBUG
- /*
- ** if debugging, look up token value in list of value vs.
- ** name pairs. 0 and negative (-1) are special values.
- ** Note: linear search is used since time is not a real
- ** consideration while debugging.
- */
- if ( zzdebug )
- {
- register int zz_i;
-
- printf( "State %d, token ", zz_state );
- if ( zzchar == 0 )
- printf( "end-of-file\n" );
- else if ( zzchar < 0 )
- printf( "-none-\n" );
- else
- {
- for ( zz_i = 0; zztoks[zz_i].t_val >= 0;
- zz_i++ )
- {
- if ( zztoks[zz_i].t_val == zzchar )
- break;
- }
- printf( "%s\n", zztoks[zz_i].t_name );
- }
- }
- #endif /* YYDEBUG */
- if ( ++zz_ps >= &zzs[ YYMAXDEPTH ] ) /* room on stack? */
- {
- zzerror( "yacc stack overflow" );
- YYABORT;
- }
- *zz_ps = zz_state;
- *++zz_pv = zzval;
-
- /*
- ** we have a new state - find out what to do
- */
- zz_newstate:
- if ( ( zz_n = zzpact[ zz_state ] ) <= YYFLAG )
- goto zzdefault; /* simple state */
- #if YYDEBUG
- /*
- ** if debugging, need to mark whether new token grabbed
- */
- zztmp = zzchar < 0;
- #endif
- if ( ( zzchar < 0 ) && ( ( zzchar = zzlex() ) < 0 ) )
- zzchar = 0; /* reached EOF */
- #if YYDEBUG
- if ( zzdebug && zztmp )
- {
- register int zz_i;
-
- printf( "Received token " );
- if ( zzchar == 0 )
- printf( "end-of-file\n" );
- else if ( zzchar < 0 )
- printf( "-none-\n" );
- else
- {
- for ( zz_i = 0; zztoks[zz_i].t_val >= 0;
- zz_i++ )
- {
- if ( zztoks[zz_i].t_val == zzchar )
- break;
- }
- printf( "%s\n", zztoks[zz_i].t_name );
- }
- }
- #endif /* YYDEBUG */
- if ( ( ( zz_n += zzchar ) < 0 ) || ( zz_n >= YYLAST ) )
- goto zzdefault;
- if ( zzchk[ zz_n = zzact[ zz_n ] ] == zzchar ) /*valid shift*/
- {
- zzchar = -1;
- zzval = zzlval;
- zz_state = zz_n;
- if ( zzerrflag > 0 )
- zzerrflag--;
- goto zz_stack;
- }
-
- zzdefault:
- if ( ( zz_n = zzdef[ zz_state ] ) == -2 )
- {
- #if YYDEBUG
- zztmp = zzchar < 0;
- #endif
- if ( ( zzchar < 0 ) && ( ( zzchar = zzlex() ) < 0 ) )
- zzchar = 0; /* reached EOF */
- #if YYDEBUG
- if ( zzdebug && zztmp )
- {
- register int zz_i;
-
- printf( "Received token " );
- if ( zzchar == 0 )
- printf( "end-of-file\n" );
- else if ( zzchar < 0 )
- printf( "-none-\n" );
- else
- {
- for ( zz_i = 0;
- zztoks[zz_i].t_val >= 0;
- zz_i++ )
- {
- if ( zztoks[zz_i].t_val
- == zzchar )
- {
- break;
- }
- }
- printf( "%s\n", zztoks[zz_i].t_name );
- }
- }
- #endif /* YYDEBUG */
- /*
- ** look through exception table
- */
- {
- register int *zzxi = zzexca;
-
- while ( ( *zzxi != -1 ) ||
- ( zzxi[1] != zz_state ) )
- {
- zzxi += 2;
- }
- while ( ( *(zzxi += 2) >= 0 ) &&
- ( *zzxi != zzchar ) )
- ;
- if ( ( zz_n = zzxi[1] ) < 0 )
- YYACCEPT;
- }
- }
-
- /*
- ** check for syntax error
- */
- if ( zz_n == 0 ) /* have an error */
- {
- /* no worry about speed here! */
- switch ( zzerrflag )
- {
- case 0: /* new error */
- zzerror( "syntax error" );
- goto skip_init;
- zzerrlab:
- /*
- ** get globals into registers.
- ** we have a user generated syntax type error
- */
- zz_pv = zzpv;
- zz_ps = zzps;
- zz_state = zzstate;
- zznerrs++;
- skip_init:
- case 1:
- case 2: /* incompletely recovered error */
- /* try again... */
- zzerrflag = 3;
- /*
- ** find state where "error" is a legal
- ** shift action
- */
- while ( zz_ps >= zzs )
- {
- zz_n = zzpact[ *zz_ps ] + YYERRCODE;
- if ( zz_n >= 0 && zz_n < YYLAST &&
- zzchk[zzact[zz_n]] == YYERRCODE) {
- /*
- ** simulate shift of "error"
- */
- zz_state = zzact[ zz_n ];
- goto zz_stack;
- }
- /*
- ** current state has no shift on
- ** "error", pop stack
- */
- #if YYDEBUG
- # define _POP_ "Error recovery pops state %d, uncovers state %d\n"
- if ( zzdebug )
- printf( _POP_, *zz_ps,
- zz_ps[-1] );
- # undef _POP_
- #endif
- zz_ps--;
- zz_pv--;
- }
- /*
- ** there is no state on stack with "error" as
- ** a valid shift. give up.
- */
- YYABORT;
- case 3: /* no shift yet; eat a token */
- #if YYDEBUG
- /*
- ** if debugging, look up token in list of
- ** pairs. 0 and negative shouldn't occur,
- ** but since timing doesn't matter when
- ** debugging, it doesn't hurt to leave the
- ** tests here.
- */
- if ( zzdebug )
- {
- register int zz_i;
-
- printf( "Error recovery discards " );
- if ( zzchar == 0 )
- printf( "token end-of-file\n" );
- else if ( zzchar < 0 )
- printf( "token -none-\n" );
- else
- {
- for ( zz_i = 0;
- zztoks[zz_i].t_val >= 0;
- zz_i++ )
- {
- if ( zztoks[zz_i].t_val
- == zzchar )
- {
- break;
- }
- }
- printf( "token %s\n",
- zztoks[zz_i].t_name );
- }
- }
- #endif /* YYDEBUG */
- if ( zzchar == 0 ) /* reached EOF. quit */
- YYABORT;
- zzchar = -1;
- goto zz_newstate;
- }
- }/* end if ( zz_n == 0 ) */
- /*
- ** reduction by production zz_n
- ** put stack tops, etc. so things right after switch
- */
- #if YYDEBUG
- /*
- ** if debugging, print the string that is the user's
- ** specification of the reduction which is just about
- ** to be done.
- */
- if ( zzdebug )
- printf( "Reduce by (%d) \"%s\"\n",
- zz_n, zzreds[ zz_n ] );
- #endif
- zztmp = zz_n; /* value to switch over */
- zzpvt = zz_pv; /* $vars top of value stack */
- /*
- ** Look in goto table for next state
- ** Sorry about using zz_state here as temporary
- ** register variable, but why not, if it works...
- ** If zzr2[ zz_n ] doesn't have the low order bit
- ** set, then there is no action to be done for
- ** this reduction. So, no saving & unsaving of
- ** registers done. The only difference between the
- ** code just after the if and the body of the if is
- ** the goto zz_stack in the body. This way the test
- ** can be made before the choice of what to do is needed.
- */
- {
- /* length of production doubled with extra bit */
- register int zz_len = zzr2[ zz_n ];
-
- if ( !( zz_len & 01 ) )
- {
- zz_len >>= 1;
- zzval = ( zz_pv -= zz_len )[1]; /* $$ = $1 */
- zz_state = zzpgo[ zz_n = zzr1[ zz_n ] ] +
- *( zz_ps -= zz_len ) + 1;
- if ( zz_state >= YYLAST ||
- zzchk[ zz_state =
- zzact[ zz_state ] ] != -zz_n )
- {
- zz_state = zzact[ zzpgo[ zz_n ] ];
- }
- goto zz_stack;
- }
- zz_len >>= 1;
- zzval = ( zz_pv -= zz_len )[1]; /* $$ = $1 */
- zz_state = zzpgo[ zz_n = zzr1[ zz_n ] ] +
- *( zz_ps -= zz_len ) + 1;
- if ( zz_state >= YYLAST ||
- zzchk[ zz_state = zzact[ zz_state ] ] != -zz_n )
- {
- zz_state = zzact[ zzpgo[ zz_n ] ];
- }
- }
- /* save until reenter driver code */
- zzstate = zz_state;
- zzps = zz_ps;
- zzpv = zz_pv;
- }
- /*
- ** code supplied by user is placed in this switch
- */
- switch( zztmp )
- {
-
- case 1:
- # line 62 "posixtm.y"
- {
- if (zzpvt[-5] >= 1 && zzpvt[-5] <= 12)
- t.tm_mon = zzpvt[-5] - 1;
- else {
- YYABORT;
- }
- if (zzpvt[-4] >= 1 && zzpvt[-4] <= 31)
- t.tm_mday = zzpvt[-4];
- else {
- YYABORT;
- }
- if (zzpvt[-3] >= 0 && zzpvt[-3] <= 23)
- t.tm_hour = zzpvt[-3];
- else {
- YYABORT;
- }
- if (zzpvt[-2] >= 0 && zzpvt[-2] <= 59)
- t.tm_min = zzpvt[-2];
- else {
- YYABORT;
- }
- } break;
- case 2:
- # line 85 "posixtm.y"
- {
- t.tm_year = zzpvt[-0];
- /* Deduce the century based on the year.
- See POSIX.2 section 4.63.3. */
- if (zzpvt[-0] <= 68)
- t.tm_year += 100;
- } break;
- case 3:
- # line 92 "posixtm.y"
- {
- t.tm_year = zzpvt[-1] * 100 + zzpvt[-0];
- if (t.tm_year < 1900) {
- YYABORT;
- } else
- t.tm_year -= 1900;
- } break;
- case 4:
- # line 99 "posixtm.y"
- {
- time_t now;
- struct tm *tmp;
-
- /* Use current year. */
- time (&now);
- tmp = localtime (&now);
- t.tm_year = tmp->tm_year;
- } break;
- case 5:
- # line 110 "posixtm.y"
- {
- t.tm_sec = 0;
- } break;
- case 6:
- # line 113 "posixtm.y"
- {
- if (zzpvt[-0] >= 0 && zzpvt[-0] <= 61)
- t.tm_sec = zzpvt[-0];
- else {
- YYABORT;
- }
- } break;
- case 7:
- # line 122 "posixtm.y"
- {
- zzval = zzpvt[-1] * 10 + zzpvt[-0];
- } break;
- }
- goto zzstack; /* reset registers in driver code */
- }
-